package com.wjc.common.utils

import android.app.Activity
import android.graphics.Color
import android.os.Build
import android.view.View
import android.view.WindowManager
import androidx.fragment.app.FragmentActivity

/**
 * ClassName: com.wjc.basemodule.base
 * Description: 沉浸式
 * JcChen on 2020.09.21.7:52 PM
 */
object StatusBarUtil {
    /**
     * 修改状态栏为全透明
     *
     * @param activity
     * @param darkMode 是否是黑色
     */
    fun transparencyBar(activity: FragmentActivity, darkMode: Boolean) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            val window = activity.window
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
            var uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            if (darkMode && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                uiFlags = uiFlags or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
            }
            window.decorView.systemUiVisibility = uiFlags
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
            window.statusBarColor = Color.TRANSPARENT
        }
    }
}